import axios from '@/axios'
import store from "@/store"
import encrypt from '@script/encrypt'

export default {
    /**
     * 更新个人信息
     * @param {Number} type 信息标志
     * @param {any} value 新数据
     * @param {Number} sid 学号
     */
    async axiosAlterInfo(type, value, sid) {
        return await axios({
            method: "PATCH",
            url: `/stu/alter/info`,
            params: {
                type: type,
                value: encrypt(value),
                sid: encrypt(sid)
            }
        })
    },
    /**
     * 登录
     * @param {Number} sid 学号
     * @param {String} passwd 密码
     */
    async entry(sid, passwd) {
        return await axios({
            url: `/stu/auth/login`,
            params: {
                sid: encrypt(sid),
                passwd: encrypt(passwd)
            },
            method: "GET"
        })
    },
    /**
     * 注册
     * @param {String} name 姓名
     * @param {Number} sid 学号
     * @param {String} dept 部门
     * @param {String} group 小组
     * @param {String} college 学院
     */
    async registry(name, sid, dept, group, college) {
        return await axios({
            url: `/stu/create/record`,
            params: {
                name: encrypt(name),
                sid: encrypt(sid),
                department: dept,
                group: group,
                college: college
            },
            method: "POST"
        })
    },
    async getStudentByDept(dept_name) {
        return await axios({
            url: `/stu/get/by-dept`,
            params: {
                dept: dept_name
            },
            method: "GET"
        })
    }
}